package com.vita.bduck.logger.helps;

/**
 *
 * 格式化元组
 * Created with IntelliJ IDEA.
 * User: Vita Hao
 * Date: 13-6-19
 * Time: 上午10:05
 * To change this template use File | Settings | File Templates.
 */
public class FormattingTuple {

    //错误信息
    private String message;

    //异常
    private Throwable throwable;

    //参数对象数组
    private Object[] argArray;


    public FormattingTuple(String message) {
        this(message, null, null);
    }

    public FormattingTuple(String message,  Object[] argArray,Throwable throwable) {
        this.message = message;

        this.throwable = throwable;
        if (throwable == null) {
            this.argArray = argArray;

        }else{
            this.argArray = trimmedCopy(argArray);
        }

    }

    /**
     * 复制对象参数
     * @param argArray
     * @return
     */
    static Object[] trimmedCopy(Object[] argArray) {
        if(argArray == null || argArray.length == 0) {
            throw new  IllegalStateException("non-sensical empty or null argument array");
        }
        final int trimemdLen = argArray.length -1;
        Object[] trimmed = new Object[trimemdLen];
        System.arraycopy(argArray, 0, trimmed, 0, trimemdLen);
        return trimmed;
    }

    public String getMessage() {
        return message;
    }

    public Throwable getThrowable() {
        return throwable;
    }

    public Object[] getArgArray() {
        return argArray;
    }
}
